<?php
!defined('QAPP') AND exit('Forbidden');

//START---------后台标签TAG功能
function admin_tags_edit($do, $postcid, $postid)
{
    $stypes = getGlobals('tags_save_new_array');
    if (!empty($stypes)) {
        if ($do == 'edit') {
            tag_remove(false, false, $postcid, $postid);
        }
        foreach ($stypes as $stype => $tags) {
            array_trim($tags);
            tag_add($tags, $stype, $postid, $postcid, 'auto');
        }
    }

    //用好清空
    setGlobals('tags_save_new_array', null);
}
//使用了tags组件，值被保存时
getHooks()->add_action('admin_tags_save', function ($params) {
    list($inputname, $newarray) = $params;
    //存储下来，给后面的动作执行
    $tags_save_new_array = getGlobals('tags_save_new_array');
    if (empty($tags_save_new_array)) $tags_save_new_array = array();
    $tags_save_new_array[$inputname] = $newarray;
    setGlobals('tags_save_new_array', $tags_save_new_array);
});
//添加文章之后
getHooks()->add_action('admin_addposted', function () {
    global $thisid, $cid;
    admin_tags_edit('add', $cid, $thisid);
});
//编辑文章之后
getHooks()->add_action('admin_editposted', function () {
    global $thisid, $cid;
    admin_tags_edit('edit', $cid, $thisid);
});
//添加测试文章之后
getHooks()->add_action('admin_add_test_posted', function () {
//不支持tag功能
});
//变量修改之后
getHooks()->add_action('admin_str_edited_loop', function () {
    global $thisid, $cid;
    admin_tags_edit('edit', $cid, $thisid);
});
//删除文章之后
getHooks()->add_action('admin_delposted', function () {
    global $thisid, $cid;
    tag_remove(false, false, $cid, $thisid);
});
//清空栏目文章之后
getHooks()->add_action('admin_clsallposted', function () {
    global $cid;
    tag_remove(false, false, $cid, false);
});
//转移文章之后
getHooks()->add_action('admin_post_moved', function () {
    global $targetcid, $cid, $id;
    tag_remove(false, false, $cid, $id);
    admin_tags_edit('add', $targetcid, $id);
});
//END---------后台标签TAG功能






